#include "savedgame.h"

SavedGame::SavedGame()
{

}

SavedGame::SavedGame(QString &saveName, int saveId, QStringList &levels, int levelPos)
{
    m_levelName = levels.at(levelPos);
    m_levels = levels;
    m_levelPos = levelPos;
    m_saveName = saveName;
    m_saveId = saveId;
    m_saveDate = QDateTime::currentDateTime();
}

QString SavedGame::toString()
{
    return m_saveName + " - " +
           m_levelName + " - " +
           m_saveDate.toString("dd/MM/yyyy hh:mm:ss");
}


QString SavedGame::getLevelName() {return this->m_saveName;}
QString SavedGame::getSaveName() {return this->m_saveName;}
int SavedGame::getSaveId() {return this->m_saveId;}
QDateTime SavedGame::getSaveDate() {return this->m_saveDate;}
QStringList SavedGame::getLevels() {return m_levels;}
int SavedGame::getLevelPos() {return m_levelPos;}


void SavedGame::serializeOut(QDataStream &out)
{
    out << this->m_levelName
        << this->m_saveDate
        << (qint32)this->m_saveId
        << this->m_saveName
        << this->m_levels
        << (qint32)this->m_levelPos;
}

void SavedGame::serializeIn(QDataStream &in)
{
    in  >> this->m_levelName
        >> this->m_saveDate
        >> this->m_saveId
        >> this->m_saveName
        >> this->m_levels
        >> this->m_levelPos;
}


QDataStream & operator << (QDataStream &out, SavedGame* savedGame)
{
    savedGame->serializeOut(out);
    return out;
}

QDataStream & operator >> (QDataStream &in,  SavedGame* savedGame)
{
    savedGame->serializeIn(in);
    return in;
}
